/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bo;

import org.ipti.br.tag.dao.OrganizationFacade;
import org.ipti.br.tag.entity.Organization;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 *
 * @author israel
 */
@Stateless
public class OrganizationBO implements Serializable {

    @Inject
    private OrganizationFacade organizationDAO;

    public OrganizationFacade getOrganizationDAO() {
        return organizationDAO;
    }

    public void create(Organization organization) {
        getOrganizationDAO().create(organization);
    }

    public void edit(Organization organization) {
        getOrganizationDAO().edit(organization);
    }

    public void remove(Organization organization) {
        getOrganizationDAO().remove(organization);
    }

    public Organization find(Object id) {
        return getOrganizationDAO().find(id);
    }

    public List<Organization> findAll() {
        return getOrganizationDAO().findAll();
    }

    public void editForSynchronization(Organization organization) {
        getOrganizationDAO().editForSynchronization(organization);
    }

    public List<Organization> getOrganizationChildren(Long organizationID) {
        return getOrganizationDAO().getOrganizationChildren(organizationID);
    }

    public List<Organization> getOrganizationDescedents(Long organizationID) {
        List<Organization> organizationList = new ArrayList<Organization>();
        organizationList.add(find(organizationID));

        for (Organization org : getOrganizationChildren(organizationID)) {
            organizationList.addAll(getOrganizationDescedents(org.getId()));
        }

        return organizationList;
    }
    
    public List<Organization> getOrganizationsByName(String organizationName) {
        return getOrganizationDAO().getOrganizationsByName(organizationName);
    }
    
    public List<Organization> getOrganizationsByPersonages(List<Long> personagesIDs) {
        return getOrganizationDAO().getOrganizationsByPersonages(personagesIDs);
    }

    public List<Organization> findAllOrder() {
        return getOrganizationDAO().findAllOrder();
    }
    
    public Organization getOrganizationByName(String organizationName) {
        return getOrganizationDAO().getOrganizationByName(organizationName);
    }
}
